package com.wzy.spring2.service;

import com.google.common.collect.Maps;
import com.wzy.spring2.dao.WebUserDao;
import com.wzy.spring2.model.WebUserDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author Weizhengyun
 * @desc
 * @date 2022/12/17 上午9:59
 */

@Service
@Slf4j
public class AccountStoreService {

    @Autowired
    private WebUserDao dao;

    public static final Map<String, WebUserDTO> accountMap = Maps.newConcurrentMap();

    public void setAccount(String webName, String account, String password) {
        if (accountMap.containsKey(webName)) {
            log.info("[getAccount] AccountStoreService. webName = {} update", webName);
        }
        log.info("[getAccount] AccountStoreService. webName = {} save", webName);
        accountMap.put(webName, WebUserDTO.builder()
                .account(account)
                .password(password).build());
    }

    public WebUserDTO getAccount(String webName) {
        if (!accountMap.containsKey(webName)) {
            log.error("[getAccount] AccountStoreService. webName = {} not exist!!", webName);
            return null;
        }
        return accountMap.get(webName);
    }

}
